#!/usr/bin/env perl
# A script used by the authors of FastBit to configure the package.
# Terse comments are provided in hoping they might be instructive for
# configuring the package on other machines.
#
use Env qw(HOME HOSTNAME PWD);
if (! ${HOSTNAME}) {
  $HOSTNAME=`hostname`;
}
print "Configuring on ${HOSTNAME}\n";
if (${HOSTNAME} =~ m/^bit/) {
  # on a Mac used by a developer, enable maintainer mode, use debug options # CC=gcc-mp-4.7 CXX=g++-mp-4.7 # CC=clang CXX=clang++
  $cmd="./configure --prefix=${HOME}/`uname -s`/fastbit --enable-maintainer-mode --with-java CFLAGS='-g -O0 -Wall -ansi' CXXFLAGS='-g -O0 -Wall -ansi'";
} elsif (${HOSTNAME} =~ m/^data5[.lbl.gov]?$/) {
  # on data5, know where is java and where to install, use extra optimization
  $cmd="./configure --enable-xopt --disable-debug --with-java=/software/jdk1.7.0 --prefix=/data/john/Linux/fastbit";
} elsif (${HOSTNAME} =~ m/^d\w+[.lbl.gov]?$/) {
  # on sdm group's linux machines, know where is java and where to install
  $cmd="./configure --enable-xopt --disable-debug --with-java=/software/jdk1.7.0 --prefix=/fastbit/`uname -s`/fastbit";
} elsif (${HOSTNAME} =~ m/^hopper\w+[.nersc.gov]?$/) {
  # on hopper at NERSC, there is a choice to be made about what compiler to use
  # print "\nPlease make sure that PrgEnv-gnu is used, for example by executing 'module swap PrgEnv-pgi PrgEnv-gnu'\n\n";
  $cmd="./configure --without-getpwuid CFLAGS='-fPIC -O' CXXFLAGS='-fPIC -O' --without-java --prefix=/project/projectdirs/m1248/hopper/gnu/fastbit";
  #$cmd="./configure CC=pgcc CXX=pgCC --without-getpwuid CFLAGS='-fPIC -O' CXXFLAGS='-fPIC -O' --without-java --prefix=/project/projectdirs/m1248/hopper/pgi/fastbit";
} elsif (${HOSTNAME} =~ m/^sith/) {# sith.ccs.ornl.gov
  # on sith at ORNL, try GNU compilers
  $cmd="./configure --prefix=${HOME}/`uname -s`/fastbit/sith-gnu --without-java --enable-xopt --disable-debug"
} elsif (${HOSTNAME} =~ m/^titan/) {#[-\w+]?[.ornl.gov]?$
  # on titan at ORNL, try GNU compilers
  $cmd="./configure --prefix=${HOME}/`uname -s`/fastbit/titan-gnu --without-java --enable-xopt --disable-debug --disable-shared --without-getpwuid"
  # on titan at ORNL, need to choose between PGI and GNU compilers
  #$cmd="env CC=pgcc CXX=pgCC ./configure --prefix=${HOME}/`uname -s`/fastbit/tital-pgi --without-java --enable-xopt --disable-debug --disable-shared"
} elsif (${HOSTNAME} =~ m/^cvr\w+[\.nersc\.gov]?$/) {
  # on carver at NERSC, use the GNU compilers, no debugging
  $cmd="./configure --without-getpwuid --enable-xopt --disable-debug --without-java --prefix=/project/projectdirs/m1248/carver/fastbit";
} elsif (defined $ENV{"NERSC_HOST"}) {
  # on other NERSC machines, use the default compilers, no debugging
  use Env qw(NERSC_HOST);
  $cmd="./configure --prefix=/project/projectdirs/m1248/${NERSC_HOST}/gcc/fastbit --without-getpwuid --disable-debug --enable-xopt";
} else {	# use all default options on generic linux/unix machines
  $cmd="./configure --prefix=${PWD}";
}
print "$cmd\n\n";
system($cmd);
